<template>
	<div>
		<el-button type="text" @click="dialogVisible=true">新增产品</el-button>
		<el-dialog
			title="新增产品"
			:visible.sync="dialogVisible">
			<el-form label-width="100px" label-position="left" v-model="form">
				<el-form-item label="产品名称" prop="name">
					<el-input v-model="form.name"></el-input>
				</el-form-item>
				<el-form-item label="产品小标题" prop="title">
					<el-input v-model="form.title"></el-input>
				</el-form-item>
				<el-form-item label="原价格" prop="prePrice">
					<el-input v-model="form.prePrice"></el-input>
				</el-form-item>
				<el-form-item label="优惠价格" prop="currentPrice">
					<el-input v-model="form.currentPrice"></el-input>
				</el-form-item>
				<el-form-item label="库存" prop="stock">
					<el-input v-model="form.stock"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button @click="commit()">提交</el-button>
				</el-form-item>
			</el-form>
		</el-dialog>
	</div>
</template>

<script>
  import {addProduct} from '@/api/admin/product.js'
	export default{
		data() {
			return {
				dialogVisible:false,
        form:{}
			}
		},
    methods: {
      commit() {
        // let formData = new FormData()
        // formData.append('name',this.form.name)
        // formData.append('subTitle',this.form.title)
        // formData.append('originalPrice',this.form.prePrice)
        // formData.append('promotePrice',this.form.currentPrice)
        // formData.append('stock',this.form.stock)
        // formData.append('category',this.$route.query.id)
		let data = {
			name:this.form.name,
			subTitle:this.form.title,
			originalPrice:this.form.prePrice,
			promotePrice:this.form.currentPrice,
			stock:this.form.stock,
			category:this.$route.query.id
		}
        addProduct(data).then(res => {
          this.$message({
            type:'success',
            message:'添加成功'
          })
          this.dialogVisible = false
          this.$emit('flash')
        })
      }
    },
	}
</script>

<style scoped>
</style>
